//
//  BaseTableViewController.m
//  pmmSS
//
//  Created by Mac book on 2017/8/29.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "BaseTableViewController.h"

@interface BaseTableViewController ()

@end

@implementation BaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setUpTableView:self.tableView];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setUpNavBar];
}

-(void)dealloc{
    NSLog(@"=====控制器%@销毁了====",self);
}




-(void)setUpNavBar{

    _titleColor = [UIColor whiteColor];
    ///子类实现
}

-(void)setUpTableView:(UITableView*)tableView{
    ///子类实现
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    NSLog(@"内存不足警告!!!!%@",self);
}


-(void)setTitleFont:(UIFont *)titleFont{
    if (_titleFont == titleFont) {
        return;
    }
    _titleFont = titleFont;
    NSMutableDictionary *titleTextAttributes = [NSMutableDictionary dictionary];

    if(self.navigationController.navigationBar.titleTextAttributes){
        titleTextAttributes = [[NSMutableDictionary alloc] initWithDictionary:self.navigationController.navigationBar.titleTextAttributes];
    }

    if(_titleFont){
        titleTextAttributes[NSFontAttributeName] = _titleFont;
    }

    self.navigationController.navigationBar.titleTextAttributes = titleTextAttributes;}

-(void)setTitleColor:(UIColor *)titleColor{
    if(_titleColor == titleColor){
        return;
    }
    _titleColor = titleColor;
    NSMutableDictionary *titleTextAttributes = [NSMutableDictionary dictionary];

    if(self.navigationController.navigationBar.titleTextAttributes){
        titleTextAttributes = [[NSMutableDictionary alloc] initWithDictionary:self.navigationController.navigationBar.titleTextAttributes];
    }

    if(_titleColor){
        titleTextAttributes[NSForegroundColorAttributeName] = _titleColor;
    }


    self.navigationController.navigationBar.titleTextAttributes = titleTextAttributes;
}


+(instancetype)controllerWith:(UITableViewStyle)tableViewStyle{
    return [[self alloc] initWithStyle:tableViewStyle];
}


-(void)setConfig:(NSDictionary *)config{
    _config =config;
    if (_config&&_config[@"title"]) {
        self.title = _config[@"title"];
    }
}


@end
